<!doctype html>
<!--
* Tabler - Premium and Open Source dashboard template with responsive and high quality UI.
* @version 1.0.0-beta20
* @link https://tabler.io
* Copyright 2018-2023 The Tabler Authors
* Copyright 2018-2023 codecalm.net Paweł Kuna
* Licensed under MIT (https://github.com/tabler/tabler/blob/master/LICENSE)
-->
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>小红薯去水印 - xhs - xiaohongshu - download- Tools</title>
  <link rel="shortcut icon" href="../templates/favicon.svg" />
  <!-- CSS files -->
  <link href="../dist/css/tabler.min.css?1692870487" rel="stylesheet" />
  <link href="../dist/css/tabler-vendors.min.css" rel="stylesheet" />
  <link href="../styles/tabler-iconify-icon.css" rel="stylesheet" />
  <link href="../templates/template.css" rel="stylesheet" />
  <link href="../dist/libs/toastr/toastr.tabler.css" rel="stylesheet" />
  <link href="../styles/xhs.css" rel="stylesheet" />

  <style>
    @import url('https://cdn.bootcdn.net/ajax/libs/inter-ui/4.0.2/inter.css');

    :root {
      --tblr-font-sans-serif: 'Inter Var', -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
    }

    body {
      font-feature-settings: "cv03", "cv04", "cv11";
    }

    .hide {
      display: none !important;
    }
  </style>
</head>

<body>
  <script src="../dist/js/demo-theme.min.js?1692870487"></script>
  <div class="page">
    <div id="header"></div>
    <!-- Navbar -->

    <div class="page-wrapper">
      <!-- Page header -->
      <div class="page-header d-print-none">
        <div class="container-xl">
          <div class="row g-2 align-items-center">
            <div class="col">
              <h2 class="page-title">小红书去水印</h2>
            </div>
          </div>
        </div>
      </div>
      <!-- Page body -->
      <div class="page-body">
        <div class="container-xl">
          <div class="card">
            <div class="row g-0">
              <div class="col-12 col-md-12 d-flex flex-column">
                <div class="card-body">
                  <div class="mb-3">
                    <label class="form-label">请输入小红书作品分享链接</label>
                    <div class="input-group input-group-flat">
                      <textarea class="form-control" rows="5" id="inputText"></textarea>
                      <span class="input-group-text" style="padding:9px 8px">
                        <a href="javascript:void(0);" class="link-secondary" onclick="$('#inputText').val('')">
                          <i class="icon icon--tabler icon--tabler--x"></i>
                        </a>
                      </span>
                    </div>
                  </div>
                  <div class="mb-3">
                    <select type="text" class="form-select" id="select-states" value="" multiple placeholder="请选择作品序号">
                      <option value="1">1</option>
                      <option value="2">2</option>
                      <option value="3">3</option>
                      <option value="4">4</option>
                      <option value="5">5</option>
                      <option value="6">6</option>
                      <option value="7">7</option>
                      <option value="8">8</option>
                      <option value="9">9</option>
                    </select>
                  </div>
                  <div class="mb-3">
                    <div class="input-group input-group-flat">
                      <input id="opusIndexs" class="form-control" placeholder="请输入作品序号,默认全部,多个用逗号隔开,如:1,2,3" />
                      <span class="input-group-text" style="padding:9px 8px">
                        <a href="javascript:void(0);" class="link-secondary" onclick="tomSelectIndex.clear();">
                          <i class="icon icon--tabler icon--tabler--x"></i>
                        </a>
                      </span>
                    </div>
                  </div>
                  <div class="mb-3">
                    <a href="javascript:void(0);" class="btn btn-outline-primary" onclick="parseShare()">
                      解析作品
                    </a>
                  </div>
                  <div id="showImage"></div>
                </div>
              </div>
            </div>
          </div>
          <button onclick="downloadImages()" class="go-to-top visible d-none" aria-label="download image">
            <i class="icon icon--tabler icon--tabler--file-download"></i>
          </button>
        </div>
      </div>
    </div>


    <div id="mask" class="mask">
      <div class="mask-content">
        <div id="maskTitle" class="mask-title">正在加载中</div>
        <div class="progress progress-sm">
          <div class="progress-bar progress-bar-indeterminate"></div>
        </div>
      </div>
    </div>

  </div>

  <!-- Libs JS -->
  <script src="../dist/js/tabler.min.js?1692870487" defer></script>
  <script src="../dist/libs/jquery-1.9.1.min.js"></script>
  <script src="../dist/libs/toastr/toastr.tabler.js"></script>
  <script src="../dist/libs/art-template/template-web.min.js"></script>
  <script src="../templates/template.js?v=1.1" defer></script>
  <script src="../dist/libs/tom-select/dist/js/tom-select.complete.min.js"></script>
  <script src="../dist/libs/fslightbox/index.js"></script>

  <script id="tpl-img-show" type="text/html">
    <% if (browserInfo.osType=='iOS' && images.length > 0) { %>
    <div class="mb-3" ng-show="images.length > 0">
      <div class="row g-2">
        <% images.forEach(function(image, index) { %>
        <div class="col-6 col-sm-4">
          <a data-fslightbox="gallery" href="<%= image %>">
            <div class="img-responsive img-responsive-1x1 rounded-3 border" style="background-image: url(<%= image %>)"></div>
          </a>
        </div>
        <% }) %>
      </div>
    </div>
    <% } %>
    <% if (browserInfo.osType!='iOS' && images.length > 0) { %>
      <div class="mb-3" ng-if="browserInfo.osType!='iOS'" ng-show="images.length > 0">
      <label class="form-label">Image Check</label>
      <div class="row g-2">
        <% images.forEach(function(image, index) { %>
        <div class="col-6 col-sm-4">
          <label class="form-imagecheck mb-2">
            <input name="form-imagecheck" type="checkbox" id="formImg[<%= index %>]" class="form-imagecheck-input">
            <span class="form-imagecheck-figure">
              <img src="<%= image %>" alt="image" class="form-imagecheck-image">
            </span>
          </label>
        </div>
        <% }) %>
      </div>
    </div> 
    <% } %>
  </script>
  <script>
    var tomSelectIndex, tomSelectIndexs;
    var browserInfo;
    function initSelect() {
      var el;
      if (window.TomSelect) {
        tomSelectIndex = new TomSelect('#opusIndexs', {
          plugins: ['remove_button'],
          create: true,
        });

        tomSelectIndexs = new TomSelect(el = document.getElementById('select-states'), {
          plugins: ['remove_button'],
          copyClassesToDropdown: false,
          dropdownParent: 'body',
          controlInput: '<input>',
          render: {
            item: function (data, escape) {
              if (data.customProperties) {
                return '<div><span class="dropdown-item-indicator">' + data.customProperties + '</span>' + escape(data.text) + '</div>';
              }
              return '<div>' + escape(data.text) + '</div>';
            },
            option: function (data, escape) {
              if (data.customProperties) {
                return '<div><span class="dropdown-item-indicator">' + data.customProperties + '</span>' + escape(data.text) + '</div>';
              }
              return '<div>' + escape(data.text) + '</div>';
            },
          },
        })
      }
    }

    $(function () {
      initSelect();
      browserInfo = detectDeviceAndOS();
    })

    // var baseUrl = "http://192.168.50.3:5556";
    var baseUrl = "/xhsapi";

    async function parseShare() {
      var inputText = $("#inputText").val().trim();
      if (inputText == "") {
        toastr.warning('请输入分享链接');
        return false;
      }
      var opusIndexs = tomSelectIndex.getValue() == "" ? [] : tomSelectIndex.getValue().split(",").map(Number);
      var opusIndexs2 = tomSelectIndexs.getValue().map(Number);
      const combinedArray = [...new Set([...opusIndexs, ...opusIndexs2])];
      if (combinedArray.length > 0) {
        var pass = true;
        combinedArray.forEach(opusIndex => {
          pass = pass && /^\d+$/.test(opusIndex)
        });
        if (!pass) {
          toastr.warning('请输入正确的作品序号');
          return false;
        }
      }

      var images = [];
      var formImg = [];
      maskShow("解析需花费一段时间，请耐心等待");
      var res = await parseXHS(inputText, combinedArray);
      //console.log(res);
      if (res.data != null) {
        var fileNameFormat = `${res.data["发布时间"].replace(/:/g, ".")}_${res.data["作者昵称"]}_${res.data["作品标题"]}_{0}.png`;

        opusName = res.data["作品标题"];
        combinedArray.forEach(index => {
          images.push(`../xhs/Download/${fileNameFormat.replace("{0}", index)}`);
          formImg.push(false);
        })

        var tplImgShow = template("tpl-img-show", {
          images: images,
          browserInfo: browserInfo
        });
        $("#showImage").html(tplImgShow);
      } else {
        toastr.error(res.message);
      }

      maskHide();
    }

    async function parseXHS(share_txt, opusIndexs) {
      // 使用正则表达式匹配链接
      // share_txt = "57 过客发布了一篇小红书笔记，快来看吧！ 😆 vb20hhsvC2z4908 😆 http://xhslink.com/B/B4Fwcy，复制本条信息，打开【小红书】App查看精彩内容！"
      const urlPattern = /https?:\/\/[\w.\/-]+/;
      const match = share_txt.match(urlPattern);

      if (match && match != null) {
        const url = match[0];
        var msg = "";
        try {
          var ret = await fetchXHS({
            "url": url,
            "download": true,
            "index": opusIndexs, //["1"]
            "skip": false
          });
          if (ret == null) {
            msg = "请求解析失败";
          }
          else if (ret.data == null || !ret.data || ret.data.length == 0) {
            msg = ret.message;
          } else {
            return ret;
          }
        } catch (e) {
          msg = "请求失败: " + e.statusText;
        }
        ret = { message: msg, data: null };

        return ret;
      } else {
        return { message: "输入的分享中没有找到作品链接地址", data: null };
      }
    };

    function fetchXHS(postData) {
      return $.ajax({
        url: baseUrl + "/xhs/detail",
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(postData),
        timeout: 2 * 60 * 1000,
        crossDomain: true
      });
    }
  </script>
</body>

</html>